// abilnpc.txt
// A very simple, naive text, like basicnpc. Creature attacks anything it hates nearby.
// Once it has won, it returns to its home. This creature can also potentially bless itself, 
// curse others, or both
// Memory Cells:
//   Cell 0 - If 0, default behavior. If 1, it doesnt fidget.
//   Cell 1,2 - Stuff done flag. If both 0, nothing. Otherwise when this is killed, set to 1.
//   Cell 3 - If nonzero, can bless itself
//   Cell 4 - If nonzero, can use slow/curse rays on others. 
//   Cell 5 - Number of state when talked to. Plays default text if 0.

begincreaturescript;

variables;

short i,target;
short used_abil;
short last_abil;
short is_hate = 1;
short did_talk = 0;
short did_alert = 0;

body;

beginstate INIT_STATE;
	set_name(ME,"General Greta");
	set_level(ME,30);
	set_boss_level(ME,2);
	set_new_abil(ME,12);
	
	if (gf(101,8) > 0) {
		erase_char(ME);
		end();
		}
		
	if ((gf(100,2) == 2) || (gf(100,6) == 2))
		is_hate = 0;
	if (is_hate == 0) {
		erase_char(46);
		erase_char(47);
		erase_char(48);
		erase_char(49);
		}
		
	last_abil = get_current_tick();
	break;

beginstate DEAD_STATE;
	sf(101,8,1);
break;

beginstate START_STATE; 
	if ((did_talk == 0) && (get_nearest_party_char(7) >= 0)) {
		did_talk = 1;
		if (is_hate == 0)
			talk_no_exit(120);
			else talk_no_exit(110);
		}
		
	// if I have a target for some reason, go attack it
	if (target_ok()) {
		if (dist_to_char(get_target()) <= 16)
			set_state(3);
			else set_foe_target(ME,-1);
		}
	
	if (get_foe_target(ME,8,0)) {
		do_attack();
		set_state(3);
		}
	if (who_shot_me() >= 0) {
		set_foe_target(ME,who_shot_me());
		do_attack();
		set_state(3);
		}

	if ((did_talk > 0) && (is_hate == 0) && (get_attitude(ME) < 10)) {
		if (dist_to_nav_point(ME,2) <= 1)
			erase_char(ME);
			else approach_nav_point(ME,2,1);
		}
		
	if (am_i_doing_action() == FALSE)
		end_combat_turn();
break;

beginstate 3; // attacking
	if (target_ok() == FALSE)
		set_state(START_STATE);

	if ((did_talk == 0) && (get_nearest_party_char(10) >= 0)) {
		did_talk = 1;
		if (is_hate == 0)
			talk_no_exit(120);
			else talk_no_exit(110);
		}
	if (did_alert == 0) {
		did_alert = 1;
		alert_char(46);
		alert_char(47);
		alert_char(48);
		alert_char(49);
		}

	used_abil = 0;
	
	if ((get_memory_cell(3) > 0) && (get_nearest_party_char(9) >= 0) && (tick_difference(last_abil,get_current_tick()) > 0) && (is_combat())) {
		if ((get_char_status(ME,1) <= 0) && (get_ran(1,0,100) < 40)) {
			run_char_animation(2,1,35);	
			print_named_str(ME,"uses a pod. She starts to move faster!");
			pc_heard_sound_delay(101,250);						
		  	place_particle_num(ME,3,0,8);
			set_char_status(ME,1,5);
			last_abil = get_current_tick();
			used_abil = 1;
			}
			else if ((get_char_status(ME,8) <= 0) && (get_ran(1,0,100) < 20)) {
				run_char_animation(2,1,35);	
				print_named_str(ME,"uses a pod. She seems much stronger.");
				pc_heard_sound_delay(101,250);						
		 	 	place_particle_num(ME,1,0,8);
				set_char_status(ME,8,6);
				set_char_status(ME,0,6);
				set_char_status(ME,16,6);
				last_abil = get_current_tick();
				used_abil = 1;
				}

		}
		
	if ((used_abil == 0) && (get_memory_cell(4) > 0) && (get_nearest_party_char(9) >= 0) && (is_combat())) {
		if ((get_ran(1,0,100) < 50) && (tick_difference(last_abil,get_current_tick()) > 0)) {
			pc_heard_sound_delay(131,250);						
		  	place_particle_num(ME,1,1,8);
			run_char_animation(2,1,35);	
			damage_char(get_target(),get_ran(get_level(ME) + get_attack_bonus(ME),1,10),1);
			
			if (get_ran(1,0,100) < 50) {// slow
				print_named_str(ME,"points a wand at you. It fires a beam of energy.");
				shoot_projectile(ME,get_target(),34);
				set_char_status(get_target(),1,-8);
				set_char_status(get_target(),0,-8);
				set_char_status(get_target(),8,-8);
			  	place_particle_num(get_target(),2,6,8);
				used_abil = 1;
				}
				else { // curse
					print_named_str(ME,"points a wand at you. It creates a cloud of static.");
					shoot_projectile(ME,get_target(),38);
				  	place_particle_num(get_target(),3,6,8);
					set_char_status(get_target(),9,-20);
					set_char_status(get_target(),11,-20);
					set_char_status(get_target(),12,-20);
					set_char_status(get_target(),13,-20);
					set_char_status(get_target(),14,-20);
					set_char_status(get_target(),15,-20);
					set_char_status(get_target(),16,-20);
					set_char_status(get_target(),19,-20);
					set_char_status(get_target(),18,-20);
					used_abil = 1;
					}

			last_abil = get_current_tick();
			}
		}
	
	if (used_abil)
		end();
			
	do_attack();
break;

beginstate TALKING_STATE;
	if (get_memory_cell(5) == 0) {
		print_str("Talking: You make a bit of small talk, but you don't learn");
		print_str("  anything interesting.");
		}
		else begin_talk_mode(get_memory_cell(5));
break;